﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using HotelManager.Model;
using HotelManager.DataAccess;

namespace HotelManager.View
{
    public partial class FormPhong : Form
    {
        PhongAccess phongAccess = new PhongAccess();
        DataTable dsPhong = new DataTable();
        public FormPhong()
        {
            InitializeComponent();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void FormPhong_Load(object sender, EventArgs e)
        {
            dsPhong = phongAccess.laytoanbophong();
            dataGridView1.DataSource = dsPhong;
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            Phong p = new Phong(txtMP1.Text, txtLP1.Text, int.Parse(txtSphong1.Text), int.Parse(txtGiaP1.Text), int.Parse(txtSDT1.Text));

            if (phongAccess.themPhong(p) == 0)
            {
                MessageBox.Show("Mã phòng không tồn tại!");
            }
            else
            {
                MessageBox.Show("Thêm thành công!");
            }
            FormPhong_Load(sender, e);
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            Phong p = new Phong(txtMP1.Text, txtLP1.Text, int.Parse(txtSphong1.Text), int.Parse(txtGiaP1.Text), int.Parse(txtSDT1.Text));

            if (phongAccess.suaPhong(p) == 0)
            {
                MessageBox.Show("Mã phòng không tồn tại!");
            }
            else
            {
                MessageBox.Show("Sửa thành công!");
            }
            FormPhong_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            Phong p = new Phong(txtMP1.Text, txtLP1.Text, int.Parse(txtSphong1.Text), int.Parse(txtGiaP1.Text), int.Parse(txtSDT1.Text));
            if (phongAccess.xoaPhong(p) == 0)
            {
                MessageBox.Show("Mã phòng không tồn tại!");
            }
            else
            {
                MessageBox.Show("Xóa thành công! ");
            }
            FormPhong_Load(sender, e);
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có muốn thoát không?", "Thông Báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                this.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FormThuePhong frmThuePhong = new FormThuePhong();
            frmThuePhong.Show();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                txtMP1 .ReadOnly = false;
                btnThem.Enabled = true;
            }
            else
            {
                txtMP1.ReadOnly = true;
                btnThem.Enabled = false;
            }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtMP1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            txtLP1.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            txtSphong1.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            txtGiaP1.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            txtSDT1.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
        }

        private void txtSphong1_TextChanged(object sender, EventArgs e)
        {

        }      
       
    }
}
